﻿using System;
using Framework.Task;
using Framework.Common;

namespace Framework.Resource
{
    /// <summary>
    /// 资源加载任务
    /// </summary>
    public class LoadAssetTask : ITask
    {
        private int m_SerialId = 0;
        private bool m_Done = false;
        private string m_PackageName;
        private string m_AssetName;
        private FrameworkAction<string, string> m_LoadStartCallback;
        private FrameworkAction<string, string, object> m_LoadSuccessCallback;
        private FrameworkAction<string, string, string> m_LoadFailureCallBack;
        private FrameworkAction<string, string, int> m_LoadUpdateCallback;
        private LoadAssetStatus m_LoadAssetStatus;
        private string[] m_DependentNames = null;

        public bool Done
        {
            get
            {
                return m_Done;        
            }
            set
            {
                m_Done = value;
            }
        }
        public int TaskId
        {
            get
            {
                return m_SerialId;
            }
        }
        public string PackageName
        {
            get
            {
                return m_PackageName;
            }
        }
        public string AssetName
        {
            get
            {
                return m_AssetName;
            }
        }
        public FrameworkAction<string, string> LoadStartCallback
        {
            get
            {
                return m_LoadStartCallback;
            }
        }
        public FrameworkAction<string, string, object> LoadSuccessCallback
        {
            get
            {
                return m_LoadSuccessCallback;
            }
        }
        public FrameworkAction<string, string, string> LoadFailureCallBack
        {
            get
            {
                return m_LoadFailureCallBack;
            }
        }
        public FrameworkAction<string, string, int> LoadUpdateCallback
        {
            get
            {
                return m_LoadUpdateCallback;
            }
        }
        public LoadAssetStatus Status
        {
            get
            {
                return m_LoadAssetStatus;
            }
            set
            {
                m_LoadAssetStatus = value;
            }
        }
        public string[] DependentNames
        {
            get
            {
                return m_DependentNames;
            }
        }

        public LoadAssetTask(string packageName, string assetName, string[] dependentNames, FrameworkAction<string, string> loadStartCallback, FrameworkAction<string, string, object> loadSuccessCallback, FrameworkAction<string, string, string> loadFailureCallBack, FrameworkAction<string, string, int> loadUpdateCallback)
        {
            m_LoadStartCallback = loadStartCallback;
            m_LoadSuccessCallback = loadSuccessCallback;
            m_LoadFailureCallBack = loadFailureCallBack;
            m_LoadUpdateCallback = loadUpdateCallback;
            m_PackageName = packageName;
            m_AssetName = assetName;
            m_SerialId = GetHashCode();
            m_Done = false;
            Status = LoadAssetStatus.None;
            m_DependentNames = dependentNames;
        }
    }
}
